package com.zangchat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.core.domain.AjaxResult;
import com.common.utils.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zangchat.service.IChatUsersService;
import com.zangchat.service.IPageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zangchat.mapper.ChatLogCashMapper;
import com.zangchat.domain.ChatLogCash;
import com.zangchat.service.IChatLogCashService;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 现金流水 服务层实现
 *
 * @author wudi
 * @date 2020-07-17
 */
@Service
public class ChatLogCashServiceImpl extends ServiceImpl<ChatLogCashMapper, ChatLogCash> implements IChatLogCashService
{
    @Autowired
    private IChatUsersService chatUsersService;
    @Autowired
    private  IPageInfoService pageInfoService;

    @Override
    public ChatLogCash initQlwShopLogCash(Integer type, Long fromId, Long userId, String orderNo, BigDecimal preCash, Integer cashType,
                                             BigDecimal cash, String remark){
        ChatLogCash chatLogCash=new ChatLogCash();
        chatLogCash.setType(type);
        chatLogCash.setFromId(fromId);
        chatLogCash.setUserId(userId);
        chatLogCash.setOrderNo(orderNo);
        chatLogCash.setPreCash(preCash);
        chatLogCash.setCashType(cashType);
        chatLogCash.setCash(cash);
        chatLogCash.setRemark(remark);
        chatLogCash.setCreateTime(new Date());
        return chatLogCash;
    }

    @Override
    public AjaxResult selectChatLogCash(Long userId, Integer cashType, int pageNum,int pageSize) {
        AjaxResult ajaxResultUser = chatUsersService.checkedUser(userId);
        if (Integer.parseInt(ajaxResultUser.get("code")+"")!=200){
            return ajaxResultUser;
        }
        Map<String,Object> paraMap=new HashMap();
        pageInfoService.initPagePageHelper(pageNum,pageSize);
        paraMap.put("dataFlag",1);
        if (cashType==1){
            paraMap.put("userId",userId);
        }
        if (cashType==-1){
            paraMap.put("fromId",userId);
        }
        List<Map<String,Object>> list=   baseMapper.selectMapList(paraMap);
        Map<String, Object> resultMap = pageInfoService.initPageInfo(list);
        return AjaxResult.success(resultMap);
    }

}